using System;
using Microsoft.DirectX.Direct3D;
using SharpWind.Resources.Creators;
using SharpWind.Tools;

namespace SharpWind.Resources
{
	public class Mesh : Resource
	{
		private Microsoft.DirectX.Direct3D.Mesh mesh = null;

		private int subsets = 1;

		public void Render()
		{
			for( int i = 0; i < this.subsets; i++ )
			{
				D3DMesh.DrawSubset( i );
			}
		}
		
		public override void Dispose()
		{
			SafeDispose.Dispose( this.mesh );
		}
		
		internal Microsoft.DirectX.Direct3D.Mesh D3DMesh
		{
			get
			{
				if( this.mesh == null || this.mesh.Disposed )
				{
					this.mesh = Engine.Instance.Content.Meshes[this.name].D3DMesh;
				}
			
				return this.mesh;
			}
			set
			{
				this.mesh = value;
			}
		}
		
		internal int Subsets
		{
			set
			{
				this.subsets = value;
			}
		}
	}
}